package com.bowen.util;

/**
 * 字段处理 源码 org.apache.commons.lang.StringUtils;
 * 
 * @author Bowen
 * @since 2021-12-03 15:38:12
 */
public class StringUtils {

  /**
   * The empty String <code>""</code>.
   * 
   * @since 2.0
   */
  public static final String EMPTY = "";

  /**
   * <p>
   * Checks if a String is whitespace, empty ("") or null.
   * </p>
   *
   * <pre>
   * StringUtils.isBlank(null)      = true
   * StringUtils.isBlank("")        = true
   * StringUtils.isBlank(" ")       = true
   * StringUtils.isBlank("bob")     = false
   * StringUtils.isBlank("  bob  ") = false
   * </pre>
   *
   * @param str the String to check, may be null
   * @return <code>true</code> if the String is null, empty or whitespace
   * @since 2.0
   */
  public static boolean isBlank(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
      return true;
    }
    for (int i = 0; i < strLen; i++) {
      if ((Character.isWhitespace(str.charAt(i)) == false)) {
        return false;
      }
    }
    return true;
  }

  /**
   * <p>
   * Checks if a String is not empty (""), not null and not whitespace only.
   * </p>
   *
   * <pre>
   * StringUtils.isNotBlank(null)      = false
   * StringUtils.isNotBlank("")        = false
   * StringUtils.isNotBlank(" ")       = false
   * StringUtils.isNotBlank("bob")     = true
   * StringUtils.isNotBlank("  bob  ") = true
   * </pre>
   *
   * @param str the String to check, may be null
   * @return <code>true</code> if the String is not empty and not null and not
   *         whitespace
   * @since 2.0
   */
  public static boolean isNotBlank(String str) {
    return !StringUtils.isBlank(str);
  }

  // Trim
  // -----------------------------------------------------------------------
  /**
   * <p>
   * Removes control characters (char &lt;= 32) from both ends of this String,
   * handling <code>null</code> by returning an empty String ("").
   * </p>
   *
   * <pre>
   * StringUtils.clean(null)          = ""
   * StringUtils.clean("")            = ""
   * StringUtils.clean("abc")         = "abc"
   * StringUtils.clean("    abc    ") = "abc"
   * StringUtils.clean("     ")       = ""
   * </pre>
   *
   * @see java.lang.String#trim()
   * @param str the String to clean, may be null
   * @return the trimmed text, never <code>null</code>
   */
  public static String clean(String str) {
    return str == null ? EMPTY : str.trim();
  }

}
